use std::ptr::null;
use crate::common::{RAW_WAKER, RAW_WAKER_VTABLE};
use std::task::{Context, RawWaker, RawWakerVTable, Waker};

pub struct Executor {
    raw_waker: RawWaker,
    raw_waker_vtable: RawWakerVTable,
    waker: Option<Waker>,
}
impl Executor {
    pub fn new() -> Self {
        let mut executor = Self {
            raw_waker:RAW_WAKER,
            raw_waker_vtable:RAW_WAKER_VTABLE,
            waker: None
        };

        executor.init();
        executor

    }
    fn init(&mut self) {
        unsafe {
            self.waker = Some(Waker::new(
                null() ,
                &RAW_WAKER_VTABLE,
            ))
        }
    }
     pub fn context(&mut self) -> Context {
        match self.waker {
            None => {
                self.init();
                self.context()
            }
            Some(ref waker) => Context::from_waker(waker),
        }
    }

}
